<!DOCTYPE html>
<html>
 <head>
  <meta charset="UTF-8">
  <meta name="author" content="Night">
  <title>jsNotes3</title>
  <style>


  </style>
 </head>
 <body>
     <div id="time"></div>
     <script>
      //计时器
       let time = document.getElementById('time')
       function getTime(){
        let d = new Date()
        let y = d.getFullYear()
        let m = d.getMonth()+1
        let day = d.getDate()
        let h = d.getHours()
        let i = d.getMinutes()
        let s = d.getSeconds()
        if(day<10||m<10){
           time.innerHTML = `${y}-0${m}-0${day} ${h}:${i}:${s}`;
        }else{
          time.innerHTML = `${y}-${m}-${day} ${h}:${i}:${s}`;
        }
        
       }
        let T = setInterval(getTime,1000)
        /*
        活动对象
        add
        this：谁调用该函数指向谁
        arguments：参数集合
                   callee
                   length
        调用函数，产生运行期上下文环境







        */
        /*function add(num1, num2) {
          console.dir(arguments) // 对象
          console.log(arguments.callee == add) // true
          console.log(arguments.length) // 1
          console.log(this) // window
          var sum = num1 + num2;
          return sum
        }
        add(1, 5)*/
        function fn () {
          let n = 1;
          // add = function () {
          //  ++n;
          //  console.log(n)
          // }
          function child() {
            ++n;
            console.log(n)
          }
          return child;
        }
        let c = fn();
        c()
        //使用后清掉内存
        c = null;
        let name = 'window';
        let object = {
          name: 'my object',
          getNameFunc:function(){
            //this => object
            console.log(this)
            let _this = this;
            return function(){
              //this => window
              //return this.name;
              return _this.name;
            }
          }
        }
        console.log(object.getNameFunc()())
        // 闭包 一次性执行
        (function(v1,v2){
          console.log(v1+v2)
        })(1,2)
        // 定义
        function fn1(v1,v2){
          console.log(v1+v2)
        }
        fn1();
        //变量
        let fn2 = function(v1,v2){
          console.log(v1+v2)
        }
        fn2();
        //new function
        let fn3 = new Function('console.log(v1+v2)')
        fn3();
        //回调函数
        let fn4 = function(v1,v2,cb){
          let sum = 0;
          for (var i = 0; i < 10; i++) {
            sum += v1*i + v2*i
          }
          cb(sum)
          return;
        }
        fn4(5,10,function(result){
          console.log(result)
        })
        // 计时器 一次
        let T1 = setTimeout(function(){
          console.log('4s后执行')
        },4000)
        let count = function(){
          console.log('你好')
        }
        // count不需加括号，此处传值，非调用
        let T2 = setTimeout(count,3000);
        let T3 = setTimeout("let a = '2s后执行';console.log(a)",2000)
        //内置函数
        let x = 1;
        eval('x++')
        console.log(x)//2
        let url = 'http://www.baidu.com?s=小米'
        console.log(url)
        //编码
        let urlencode = 'http://www.baidu.com?s=' + escape('小米');
        console.log(urlencode)
        //解码
        let urlencode = unescape(urlencode)
        console.log(urlencode)
     </script>
 </body>
 </html>